//
//  TestDateTime.m
//  xsd2cocoa
//
//  Created by Uwe Pachler on 03.01.14.
//
//

#import <SenTestingKit/SenTestingKit.h>

#import "DTTestDateTime.h"

@interface TestDateTime : SenTestCase {
	NSBundle* bundle;
}

@end


@implementation TestDateTime

NSDate* dateFromStringFmt(NSString* dateStr, NSString* format){
	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
	[dateFormatter setDateFormat:format];
	NSDate* date = [dateFormatter dateFromString:dateStr];
	return date;
}

NSDate* dateFromStringTZ(NSString* dateStr){
	return dateFromStringFmt(dateStr, @"yyyy-MM-dd HH:mm:ss Z");
}

NSDate* dateFromString(NSString* dateStr) {
	NSDate* date = dateFromStringFmt(dateStr, @"yyyy-MM-dd HH:mm:ss");
//	return [date dateByAddingTimeInterval:-[[NSTimeZone localTimeZone] secondsFromGMTForDate:date]];
	return date;
}

- (void)testDateTime
{
    NSURL *xml1URL = [bundle URLForResource:@"testDateTime" withExtension:@"xml"];
    
    NSData* fileData = [NSData dataWithContentsOfURL: xml1URL];
    
    DTTestDateTime* dt = [DTTestDateTime fromTestDateTime: fileData];
    
    STAssertNotNil( dt, @"date read");
	NSDate* dateWithTimeZone = dateFromStringTZ(@"2002-10-10 12:00:00 -0500");
    STAssertEqualObjects(dateWithTimeZone, dt.dateWithTimeZone, @"dateWithTimeZone");
	
	NSDate* dateWithoutTimeZone = dateFromString(@"2002-10-10 12:00:00");
    STAssertEqualObjects(dateWithoutTimeZone, dt.dateWithoutTimeZone, @"dateWithoutTimeZone");
	
	NSDate* dateWithZeroTimeZone = dateFromStringTZ(@"2002-10-10 12:00:00 +0000");
    STAssertEqualObjects(dateWithZeroTimeZone, dt.dateWithZeroTimeZone, @"dateWithZeroTimeZone");

}

-(void)setUp {
    bundle = [[NSBundle bundleForClass:[TestDateTime class]] retain];
}


@end
